/*
 * @Author: Huangdong
 * @Date: 2022-03-28 15:40:33
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @LastEditTime: 2025-04-14 14:25:16
 * @FilePath: \02.bldinsure\src\utils\filters.js
 * @Description:
 *
 *
 */
const SysTemStatus = [
  {
    value: "0",
    label: "未预收",
  },
  {
    value: "1",
    label: "未承保",
  },
  {
    value: "2",
    label: "拒保",
  },
  {
    value: "3",
    label: "已承保",
  },
  {
    value: "4",
    label: "撤单",
  },
  {
    value: "5",
    label: "犹退",
  },
  {
    value: "6",
    label: "退保",
  },
  {
    value: "7",
    label: "完成",
  }, //(用于表示可以结算佣金)
  {
    value: "8",
    label: "支付成功",
  },
  {
    value: "9",
    label: "支付收费中",
  },
  {
    value: "10",
    label: "支付失败",
  },
  {
    value: "11",
    label: "承保失败",
  },
  {
    value: "12",
    label: "人核中",
  },
  {
    value: "13",
    label: "转人工核保承保中",
  },
  {
    value: "14",
    label: "已回执",
  },
  {
    value: "15",
    label: "承保中",
  },
  {
    value: "16",
    label: "核保失败",
  },
  {
    value: "17",
    label: "待支付",
  },
  {
    value: "18",
    label: "人核（函件待处理）",
  },
  {
    value: "19",
    label: "人核（函件已处理）",
  },
  {
    value: "20",
    label: "核保中",
  },
  {
    value: "21",
    label: "核保成功，待打款",
  },
];
const orderStatusName = (num) => {
  let res = "未预收";
  const target = SysTemStatus.find((item) => item.value == num);
  if (target) {
    res = target.label;
  }
  return res;
};
const orderStatusClass = (num) => {
  if (num > 5) {
    return "success";
  }
  return "danger";
};

const insureYearName = (val, insuYearType) => {
  if (insuYearType === "A") {
    if (val === "106") {
      return "终身";
    } else {
      return "保至" + val + "岁";
    }
  } else if (insuYearType === "D") {
    return val;
  } else {
    if (val === "106") {
      return "终身";
    }
    return val + "年";
  }
};
const payendYearName = (val) => {
  return val === "趸交" ? "趸交" : val + "年交";
};

const riskAmntFormat = (val) => {
  if (val > 10000) {
    return val % 10000 === 0 ? val / 10000 + "万元" : val + "元";
  } else {
    return !val || val === 0 ? "0" : val + "元";
  }
};

/**
 * @Author: ChunLai
 * @Date: 2022-06-17 09:12:08
 * @description: 隐藏手机号中间4位
 * @param {*} phone
 * @return {*}
 */
const tellPhoneFormat = (phone) => {
  phone += "";
  // phone.substring(0, 3) + '****' + phone.substring(7);
  return phone.replace(/(\d{3})\d*(\d{4})/g, "$1***$2");
};

/**
 * @Author: ChunLai
 * @Date: 2021-05-20 11:17:48
 * @description: 金额格式化
 * @param {*} number // 保留几位小数
 * @param {*} decimals // 保留几位小数
 * @param {*} dec_point // 小数点符号
 * @param {*} thousands_sep // 千分位符号
 * @return {*}
 */
const moneyFormat = (number, decimals, dec_point, thousands_sep) => {
  number = (number + "").replace(/[^0-9+-Ee.]/g, "");
  var n = !isFinite(+number) ? 0 : +number,
    prec = !isFinite(+decimals) ? 2 : Math.abs(decimals),
    sep = typeof thousands_sep === "undefined" ? "," : thousands_sep,
    dec = typeof dec_point === "undefined" ? "." : dec_point,
    s = "",
    toFixedFix = function (n, prec) {
      var k = Math.pow(10, prec);
      return "" + Math.ceil(n * k) / k;
    };

  s = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
  var re = /(-?\d+)(\d{3})/;
  while (re.test(s[0])) {
    s[0] = s[0].replace(re, "$1" + sep + "$2");
  }

  if ((s[1] || "").length < prec) {
    s[1] = s[1] || "";
    s[1] += new Array(prec - s[1].length + 1).join("0");
  }
  return s.join(dec);
};

/**
 * @Author: ChunLai
 * @Date: 2022-06-17 08:59:14
 * @description: 身份证号码格式化
 * @param {*} val
 * @param {*} type 格式化类型: s保密中间数字 c分割式
 * @return {*}
 */
const idNumFormat = (val, type = "c") => {
  let res = "";
  if (type === "s") {
    // res = val.substring(0, 4) + '******' + val.substring(14);
    res = val.replace(/\D/g, "").replace(/(\d{6})\d*(\d{4})/g, "$1********$2");
  } else {
    res = val.replace(/\D/g, "").replace(/(\d{6})(\d{8})(?=\d)/g, "$1 $2 ");
  }
  return res;
};

/**
 * @Author: ChunLai
 * @Date: 2022-06-17 09:08:01
 * @description: 将数字转化为千分位格式
 * @param {Number} num
 * @return {*}
 */
const toDecimalMark = (num, symbol = "2") => {
  let resMoney = 0;
  if (symbol === "2") {
    // 没有货币符号
    resMoney = Number(num).toLocaleString("zh", {
      currency: "cny",
    }); // 6,393.51
  } else {
    resMoney = Number(num).toLocaleString("zh", {
      style: "currency",
      currency: "cny",
    }); // ¥6,393.51
  }
  return resMoney;
};
/**
 * @Author: ChunLai
 * @Date: 2022-06-27 16:17:34
 * @description: 设置证件的背景图
 * @param {*} dataBase
 * @param {*} ptype 1正面 2反面
 * @return {*}
 */
const setCardBackground = (dataBase, ptype = "1") => {
  let picName = "";
  if (dataBase.type === "bank") {
    picName = "eg_bank";
  } else {
    if (dataBase.idType === "0") {
      picName = ptype === "1" ? "eg_sfz1" : "eg_sfz2";
    } else if (dataBase.idType === "3") {
      picName = ptype === "1" ? "eg_hkb_1" : "eg_hkb_2";
    } else {
      picName = "eg_common";
    }
  }
  return `https://wxou.mschn.cn/app_h5/insurepics/img/${picName}.png`;
};

const sexToLabelValue = (val = "") => {
  let res = val.toString() === "1" ? "女" : "男";
  return res;
};

export default {
  orderStatusName,
  orderStatusClass,
  insureYearName,
  payendYearName,
  riskAmntFormat,
  moneyFormat,
  tellPhoneFormat,
  idNumFormat,
  toDecimalMark,
  setCardBackground,
  sexToLabelValue,
};
